//	AUTHOR:			ENRICO CANTONI
//	CREATED: 		JUNE 2, 2022
//	MODIFIED:		JUNE 2, 2022
//	DESCRIPTION:	Cleans 2008, 2010, 2012, 2014, 2016, and 2018
//					CPS self-reported turnout data.
//					The first part of the file is the standard CPS IPUMS
//					dofile reading the raw dat file.

********************************************************************************
********************************************************************************

*** DAT READING (GENERATED FROM IPUMS) ***

cd ${data_raw_CPS}

* NOTE: You need to set the Stata working directory to the path
* where the data file is located.

set more off

clear
quietly infix               ///
  int     year       1-4    ///
  long    serial     5-9    ///
  byte    month      10-11  ///
  double  hwtfinl    12-21  ///
  double  cpsid      22-35  ///
  byte    pernum     36-37  ///
  double  wtfinl     38-51  ///
  double  cpsidp     52-65  ///
  byte    age        66-67  ///
  byte    sex        68-68  ///
  byte    vowhynot   69-70  ///
  byte    voynotreg  71-72  ///
  byte    votehow    73-74  ///
  byte    votewhen   75-76  ///
  byte    voreghow   77-78  ///
  int     voteres    79-81  ///
  byte    voteresp   82-83  ///
  byte    voted      84-85  ///
  byte    voreg      86-87  ///
  double  vosuppwt   88-97  ///
  using `"cps_00003.dat"'

replace hwtfinl   = hwtfinl   / 10000
replace wtfinl    = wtfinl    / 10000
replace vosuppwt  = vosuppwt  / 10000

format hwtfinl   %10.4f
format cpsid     %14.0f
format wtfinl    %14.4f
format cpsidp    %14.0f
format vosuppwt  %10.4f

label var year      `"Survey year"'
label var serial    `"Household serial number"'
label var month     `"Month"'
label var hwtfinl   `"Household weight, Basic Monthly"'
label var cpsid     `"CPSID, household record"'
label var pernum    `"Person number in sample unit"'
label var wtfinl    `"Final Basic Weight"'
label var cpsidp    `"CPSID, person record"'
label var age       `"Age"'
label var sex       `"Sex"'
label var vowhynot  `"Reason why eligible voter did not vote"'
label var voynotreg `"Reason why eligible voter did not register to vote"'
label var votehow   `"Method of voting in the most recent November election"'
label var votewhen  `"Voted on or before election day"'
label var voreghow  `"Method of registering to vote"'
label var voteres   `"Duration of residence at current address"'
label var voteresp  `"Self or proxy respondent for voter supplement"'
label var voted     `"Voted for the most recent November election"'
label var voreg     `"Registered for the most recent November election"'
label var vosuppwt  `"Voter Supplement Weight"'

label define month_lbl 01 `"January"'
label define month_lbl 02 `"February"', add
label define month_lbl 03 `"March"', add
label define month_lbl 04 `"April"', add
label define month_lbl 05 `"May"', add
label define month_lbl 06 `"June"', add
label define month_lbl 07 `"July"', add
label define month_lbl 08 `"August"', add
label define month_lbl 09 `"September"', add
label define month_lbl 10 `"October"', add
label define month_lbl 11 `"November"', add
label define month_lbl 12 `"December"', add
label values month month_lbl

label define age_lbl 00 `"Under 1 year"'
label define age_lbl 01 `"1"', add
label define age_lbl 02 `"2"', add
label define age_lbl 03 `"3"', add
label define age_lbl 04 `"4"', add
label define age_lbl 05 `"5"', add
label define age_lbl 06 `"6"', add
label define age_lbl 07 `"7"', add
label define age_lbl 08 `"8"', add
label define age_lbl 09 `"9"', add
label define age_lbl 10 `"10"', add
label define age_lbl 11 `"11"', add
label define age_lbl 12 `"12"', add
label define age_lbl 13 `"13"', add
label define age_lbl 14 `"14"', add
label define age_lbl 15 `"15"', add
label define age_lbl 16 `"16"', add
label define age_lbl 17 `"17"', add
label define age_lbl 18 `"18"', add
label define age_lbl 19 `"19"', add
label define age_lbl 20 `"20"', add
label define age_lbl 21 `"21"', add
label define age_lbl 22 `"22"', add
label define age_lbl 23 `"23"', add
label define age_lbl 24 `"24"', add
label define age_lbl 25 `"25"', add
label define age_lbl 26 `"26"', add
label define age_lbl 27 `"27"', add
label define age_lbl 28 `"28"', add
label define age_lbl 29 `"29"', add
label define age_lbl 30 `"30"', add
label define age_lbl 31 `"31"', add
label define age_lbl 32 `"32"', add
label define age_lbl 33 `"33"', add
label define age_lbl 34 `"34"', add
label define age_lbl 35 `"35"', add
label define age_lbl 36 `"36"', add
label define age_lbl 37 `"37"', add
label define age_lbl 38 `"38"', add
label define age_lbl 39 `"39"', add
label define age_lbl 40 `"40"', add
label define age_lbl 41 `"41"', add
label define age_lbl 42 `"42"', add
label define age_lbl 43 `"43"', add
label define age_lbl 44 `"44"', add
label define age_lbl 45 `"45"', add
label define age_lbl 46 `"46"', add
label define age_lbl 47 `"47"', add
label define age_lbl 48 `"48"', add
label define age_lbl 49 `"49"', add
label define age_lbl 50 `"50"', add
label define age_lbl 51 `"51"', add
label define age_lbl 52 `"52"', add
label define age_lbl 53 `"53"', add
label define age_lbl 54 `"54"', add
label define age_lbl 55 `"55"', add
label define age_lbl 56 `"56"', add
label define age_lbl 57 `"57"', add
label define age_lbl 58 `"58"', add
label define age_lbl 59 `"59"', add
label define age_lbl 60 `"60"', add
label define age_lbl 61 `"61"', add
label define age_lbl 62 `"62"', add
label define age_lbl 63 `"63"', add
label define age_lbl 64 `"64"', add
label define age_lbl 65 `"65"', add
label define age_lbl 66 `"66"', add
label define age_lbl 67 `"67"', add
label define age_lbl 68 `"68"', add
label define age_lbl 69 `"69"', add
label define age_lbl 70 `"70"', add
label define age_lbl 71 `"71"', add
label define age_lbl 72 `"72"', add
label define age_lbl 73 `"73"', add
label define age_lbl 74 `"74"', add
label define age_lbl 75 `"75"', add
label define age_lbl 76 `"76"', add
label define age_lbl 77 `"77"', add
label define age_lbl 78 `"78"', add
label define age_lbl 79 `"79"', add
label define age_lbl 80 `"80"', add
label define age_lbl 81 `"81"', add
label define age_lbl 82 `"82"', add
label define age_lbl 83 `"83"', add
label define age_lbl 84 `"84"', add
label define age_lbl 85 `"85"', add
label define age_lbl 86 `"86"', add
label define age_lbl 87 `"87"', add
label define age_lbl 88 `"88"', add
label define age_lbl 89 `"89"', add
label define age_lbl 90 `"90 (90+, 1988-2002)"', add
label define age_lbl 91 `"91"', add
label define age_lbl 92 `"92"', add
label define age_lbl 93 `"93"', add
label define age_lbl 94 `"94"', add
label define age_lbl 95 `"95"', add
label define age_lbl 96 `"96"', add
label define age_lbl 97 `"97"', add
label define age_lbl 98 `"98"', add
label define age_lbl 99 `"99+"', add
label values age age_lbl

label define sex_lbl 1 `"Male"'
label define sex_lbl 2 `"Female"', add
label define sex_lbl 9 `"NIU"', add
label values sex sex_lbl

label define vowhynot_lbl 01 `"Illness or disability (own or family's)"'
label define vowhynot_lbl 02 `"Out of town or away from home"', add
label define vowhynot_lbl 03 `"Forgot to vote (or send in absentee ballot)"', add
label define vowhynot_lbl 04 `"Not interested, felt my vote wouldn't make a difference"', add
label define vowhynot_lbl 05 `"Too busy, conflicting work or school schedule"', add
label define vowhynot_lbl 06 `"Transportation problems"', add
label define vowhynot_lbl 07 `"Didn't like candidates or campaign issues"', add
label define vowhynot_lbl 08 `"Registration problems (i.e., didn't receive absentee ballot, not registered in current location)"', add
label define vowhynot_lbl 09 `"Bad weather conditions"', add
label define vowhynot_lbl 10 `"Inconvenient polling place or hours or lines too long"', add
label define vowhynot_lbl 11 `"Other"', add
label define vowhynot_lbl 12 `"Concerns about the COVID-19 pandemic"', add
label define vowhynot_lbl 96 `"Refused"', add
label define vowhynot_lbl 97 `"Don't know"', add
label define vowhynot_lbl 98 `"No Response"', add
label define vowhynot_lbl 99 `"NIU"', add
label values vowhynot vowhynot_lbl

label define voynotreg_lbl 01 `"Did not meet registration deadlines"'
label define voynotreg_lbl 02 `"Did not know where or how to register"', add
label define voynotreg_lbl 03 `"Did not meet residency requirements/did not live here long enough"', add
label define voynotreg_lbl 04 `"Permanent illness or disability"', add
label define voynotreg_lbl 05 `"Difficulty with English"', add
label define voynotreg_lbl 06 `"Not interested in the election or not involved in politics"', add
label define voynotreg_lbl 07 `"My vote would not make a difference"', add
label define voynotreg_lbl 08 `"Not eligible to vote"', add
label define voynotreg_lbl 09 `"Other reason"', add
label define voynotreg_lbl 10 `"Concerns about the COVID-19 pandemic"', add
label define voynotreg_lbl 96 `"Refused"', add
label define voynotreg_lbl 97 `"Don't know"', add
label define voynotreg_lbl 98 `"No Response"', add
label define voynotreg_lbl 99 `"NIU"', add
label values voynotreg voynotreg_lbl

label define votehow_lbl 01 `"In person"'
label define votehow_lbl 02 `"By mail"', add
label define votehow_lbl 97 `"Don't know"', add
label define votehow_lbl 96 `"Refused"', add
label define votehow_lbl 98 `"No Response"', add
label define votehow_lbl 99 `"NIU"', add
label values votehow votehow_lbl

label define votewhen_lbl 01 `"On election day"'
label define votewhen_lbl 02 `"Before election day"', add
label define votewhen_lbl 96 `"Refused"', add
label define votewhen_lbl 97 `"Don't know"', add
label define votewhen_lbl 98 `"No Response"', add
label define votewhen_lbl 99 `"NIU"', add
label values votewhen votewhen_lbl

label define voreghow_lbl 01 `"At a department of motor vehicles"'
label define voreghow_lbl 02 `"At a public assistance agency"', add
label define voreghow_lbl 03 `"Registered by mail"', add
label define voreghow_lbl 04 `"At a school, hospital, or on campus"', add
label define voreghow_lbl 05 `"Went to a town hall or county/government registration office"', add
label define voreghow_lbl 06 `"Filled out form at a registration drive"', add
label define voreghow_lbl 07 `"Registered at polling place"', add
label define voreghow_lbl 08 `"Registered using the Internet or online"', add
label define voreghow_lbl 09 `"Other"', add
label define voreghow_lbl 96 `"Refused"', add
label define voreghow_lbl 97 `"Don't know"', add
label define voreghow_lbl 98 `"No Response"', add
label define voreghow_lbl 99 `"NIU"', add
label values voreghow voreghow_lbl

label define voteres_lbl 010 `"Less than 1 year"'
label define voteres_lbl 011 `"Less than 1 month"', add
label define voteres_lbl 012 `"1-6 months"', add
label define voteres_lbl 013 `"7-11 months"', add
label define voteres_lbl 020 `"1-2 years"', add
label define voteres_lbl 030 `"3 or more years"', add
label define voteres_lbl 031 `"3-4 years"', add
label define voteres_lbl 032 `"3-5 years"', add
label define voteres_lbl 033 `"5 years or longer"', add
label define voteres_lbl 034 `"6 years or longer"', add
label define voteres_lbl 035 `"6-9 years"', add
label define voteres_lbl 036 `"10 years or longer"', add
label define voteres_lbl 996 `"Refused"', add
label define voteres_lbl 997 `"Don't know"', add
label define voteres_lbl 998 `"No Response"', add
label define voteres_lbl 999 `"NIU"', add
label values voteres voteres_lbl

label define voteresp_lbl 01 `"Self"'
label define voteresp_lbl 02 `"Proxy"', add
label define voteresp_lbl 09 `"NIU"', add
label values voteresp voteresp_lbl

label define voted_lbl 01 `"Did not vote"'
label define voted_lbl 02 `"Voted"', add
label define voted_lbl 96 `"Refused"', add
label define voted_lbl 97 `"Don't know"', add
label define voted_lbl 98 `"No Response"', add
label define voted_lbl 99 `"Not in universe"', add
label values voted voted_lbl

label define voreg_lbl 01 `"Did not register"'
label define voreg_lbl 02 `"Registered"', add
label define voreg_lbl 96 `"Refused"', add
label define voreg_lbl 97 `"Don't know"', add
label define voreg_lbl 98 `"Not reported / Not available"', add
label define voreg_lbl 99 `"Not in universe"', add
label values voreg voreg_lbl

********************************************************************************
********************************************************************************

*** (OWN) FINAL HOUSE-KEEPING ***

// Keep only obs in universe of CPS voting registration supplement
drop if voted == "Not in universe":voted_lbl

// Recode voting
rename voted temp
gen voted = temp == "Voted":voted_lbl

// Collapse by gender-age
gcollapse (mean) mn_voted = voted [aw=vosuppwt], by(age sex)

compress
order _all, alphabetic
gisid age sex
sort age sex
save ${CPS_clean}, replace
